<?php

class Koperasi_model{
	private $db;

	function __construct(){
		require_once('cruds.php');
		
		$this->db = new CRUDS();
	}
	
	function get_prov($id_prov){
		$this->db->select('*');
		$this->db->from('provinsi');
		$this->db->where('IDPROPINSI = '.$id_prov);
		
		$query = $this->db->get();
		return $query;
	}
	
	function get_koperasi_produk($id_kop){
		$this->db->select('*');
		$this->db->from('produk');
		$this->db->inner_join('koperasi', 'koperasi.IDKOPERASI = produk.IDKOPERASI');
		$this->db->where('koperasi.IDKOPERASI = '.$id_kop);
		
		$query = $this->db->get();
		return $query;
	}
	
	function get_foto($id_foto){
		$this->db->select('*');
		$this->db->from('foto');
		$this->db->where('IDFOTO = '.$id_foto);
		
		$query = $this->db->get();
		return $query;
	}
	
	function get_besaran($id_besaran){
		$this->db->select('*');
		$this->db->from('besaran');
		$this->db->where('IDBESARAN = '.$id_besaran);
		
		$query = $this->db->get();
		return $query;
	}
	
	function get_kota($id_kota){
		$this->db->select('*');
		$this->db->from('kota');
		$this->db->where('IDKOTA = '.$id_kota);
		
		$query = $this->db->get();
		return $query;
	}
	
	function get_koperasi_data_from_iduser($id_user){
		$this->db->select('*');
		$this->db->from('koperasi');
		$this->db->where('IDUSER = '.$id_user);
		
		$query = $this->db->get();
		return $query;
	}
	
	function get_koperasi_data(){
		$this->db->select('*');
		$this->db->from('koperasi');
		$this->db->inner_join('kota', 'kota.IDKOTA = koperasi.IDKOTA');
		$this->db->join('provinsi', 'kota.IDPROPINSI = provinsi.IDPROPINSI');
		
		$query = $this->db->get();
		return $query;
	}
	
	function get_koperasi_data_param($par){
		$this->db->select('*');
		$this->db->from('koperasi');
		$this->db->inner_join('kota', 'kota.IDKOTA = koperasi.IDKOTA');
		$this->db->join('provinsi', 'kota.IDPROPINSI = provinsi.IDPROPINSI');
		$this->db->where($par);
		
		$query = $this->db->get();
		return $query;
	}
	
	function delete_kop($id_kop){
		$this->db->where('IDKOPERASI = '.$id_kop);
		$this->db->delete('koperasi');
	}

}

?>